The Widget class provides static methods and properties to interact with home screen widgets created using the Scripting app. This API enables rendering widgets, handling configuration parameters, previewing widget layouts, and managing widget timelines.
WidgetThis class cannot be instantiated. All its members are static.
Widget.family: WidgetFamilyReturns the widget family configured by the user. The WidgetFamily determines the size and layout constraints of the widget.
Common values include:
"systemSmall" – small widget"systemMedium" – medium widget"systemLarge" – large widget"accessoryRectangular" – Lock Screen rectangular widget"accessoryCircular" – Lock Screen circular widgetType:
WidgetFamily
Widget.displaySize: WidgetDisplaySizeReturns the widget’s display size in points (width and height), depending on its family and the device's screen.
Type:
{ width: number; height: number }
Widget.parameter: stringReturns the value of the parameter configured in the widget’s settings when the script is executed via a home screen widget tap. This is useful for customizing widget content dynamically based on user-defined input.
Type:
string
Widget.present(element: VirtualNode, reloadPolicy?: WidgetReloadPolicy): voidRenders the widget UI using a React-like virtual node (JSX.Element).
You can optionally specify a reload policy to instruct the system when to request an updated timeline.
element (VirtualNode) – A JSX element representing the widget UI tree.reloadPolicy (WidgetReloadPolicy, optional) – Specifies when WidgetKit should request a new timeline. Defaults to atEnd.Returns:
void
Widget.preview(options?: PreviewOptions): Promise<void>Previews the widget with the specified configuration. This method is available only in index.tsx, not in widget.tsx or intent.tsx.
options (optional) – Configuration for previewing the widget.Returns:
Promise<void>Throws an error if parameters are not formatted correctly.
Widget.reloadAll(): voidRequests WidgetKit to reload the timelines for all widgets created using the Scripting app. This is useful when the data or appearance of widgets may have changed and needs to be refreshed.
Returns:
void
WidgetFamilyA string enum representing available widget sizes. Typical values:
WidgetDisplaySizeAn object representing the widget’s current width and height in points:
WidgetReloadPolicyAn object specifying when WidgetKit should request a new timeline:
Widget.present should be used inside widget.tsx to define and display the actual widget content.Widget.preview is a development utility used in index.tsx to simulate how widgets look and behave with different parameters.Script.exit() at the end of the widget script to ensure proper lifecycle handling.Widget.parameter as JSON if it contains structured data.